[compiler-rt][profile] Add COMPILER_RT_BUILD_PROFILE_ROCM option - #200127
Merged
Conversation
InstrProfilingPlatformROCm.cpp (added in 5db1364) is currently built into every non-baremetal libclang_rt.profile, but not all hosts support it (e.g. it fails to link on Darwin, where __llvm_write_custom_profile is unavailable). Add a COMPILER_RT_BUILD_PROFILE_ROCM CMake option (defaulting off on Apple, on elsewhere) to allow that host to opt out.
|
@llvm/pr-subscribers-pgo Author: Guy David (guy-david) ChangesInstrProfilingPlatformROCm.cpp (added in 5db1364 or #177665) is currently built into every non-baremetal libclang_rt.profile, but not all hosts support it (e.g. it fails to link on Darwin, where __llvm_write_custom_profile is unavailable). Add a COMPILER_RT_BUILD_PROFILE_ROCM CMake option (defaulting off on Apple, on elsewhere) to allow that host to opt out. Full diff: https://github.com/llvm/llvm-project/pull/200127.diff 3 Files Affected:
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index e88321d822f84..39034fd9ba67d 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -322,6 +322,15 @@ option(COMPILER_RT_USE_ATOMIC_LIBRARY "Use compiler-rt atomic instead of libatom
option(COMPILER_RT_PROFILE_BAREMETAL "Build minimal baremetal profile library" OFF)
+set(DEFAULT_COMPILER_RT_BUILD_PROFILE_ROCM ON)
+if(APPLE)
+ set(DEFAULT_COMPILER_RT_BUILD_PROFILE_ROCM OFF)
+endif()
+option(COMPILER_RT_BUILD_PROFILE_ROCM
+ "Build the host-side ROCm/HIP device profile collection runtime"
+ ${DEFAULT_COMPILER_RT_BUILD_PROFILE_ROCM})
+mark_as_advanced(COMPILER_RT_BUILD_PROFILE_ROCM)
+
include(config-ix)
#================================
diff --git a/compiler-rt/lib/profile/CMakeLists.txt b/compiler-rt/lib/profile/CMakeLists.txt
index 36e6b5a6a21c1..b8745696bc6ce 100644
--- a/compiler-rt/lib/profile/CMakeLists.txt
+++ b/compiler-rt/lib/profile/CMakeLists.txt
@@ -89,11 +89,13 @@ if (NOT COMPILER_RT_PROFILE_BAREMETAL)
list(APPEND PROFILE_SOURCES
GCDAProfiling.c
InstrProfilingFile.c
- InstrProfilingPlatformROCm.cpp
InstrProfilingRuntime.cpp
InstrProfilingUtil.c
InstrProfilingValue.c
)
+ if(COMPILER_RT_BUILD_PROFILE_ROCM)
+ list(APPEND PROFILE_SOURCES InstrProfilingPlatformROCm.cpp)
+ endif()
endif()
set(PROFILE_HEADERS
@@ -156,6 +158,12 @@ if(COMPILER_RT_PROFILE_BAREMETAL)
-DCOMPILER_RT_PROFILE_BAREMETAL=1)
endif()
+if(COMPILER_RT_BUILD_PROFILE_ROCM)
+ set(EXTRA_FLAGS
+ ${EXTRA_FLAGS}
+ -DCOMPILER_RT_BUILD_PROFILE_ROCM=1)
+endif()
+
set(PROFILE_OBJECT_LIBS)
if(COMPILER_RT_HAS_INTERCEPTION AND NOT COMPILER_RT_PROFILE_BAREMETAL)
# RTInterception references __sanitizer_internal_{memcpy,memset,memmove} and other
diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 2200f07e70acc..9ea5a2638fac9 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -50,11 +50,13 @@
* and the address test at the call site would fold to true.
* Windows: __declspec(selectany) is data-only, and the ROCm interceptor path
* is not used there, so keep the original strong extern. */
+#if COMPILER_RT_BUILD_PROFILE_ROCM
#if defined(_WIN32)
extern int __llvm_profile_hip_collect_device_data(void);
#else
__attribute__((weak)) int __llvm_profile_hip_collect_device_data(void);
#endif
+#endif
/* From where is profile name specified.
* The order the enumerators define their
@@ -1217,11 +1219,13 @@ int __llvm_profile_write_file(void) {
* InstrProfilingPlatformROCm.o is in the link, which happens when the program
* references other ROCm-runtime symbols (HIP-with-PGO). Warning on failure is
* handled inside the callee. */
+#if COMPILER_RT_BUILD_PROFILE_ROCM
#if defined(_WIN32)
(void)__llvm_profile_hip_collect_device_data();
#else
if (&__llvm_profile_hip_collect_device_data)
(void)__llvm_profile_hip_collect_device_data();
+#endif
#endif
// Restore SIGKILL.
|
zmodem
added a commit
that referenced
this pull request
Jun 3, 2026
…201416) This broke profiling builds on Windows by switching the profile library to link against the dynamic CRT; see discussion on the PR. There were already a number of issues reported and fixed after this PR. Rather than piling on the fixes (and this one may need some work), revert back to green for now to let the project recover. This reverts commit 5db1364. Additionally, this reverts the followup PRs in 635e120, 2766733, 4c33844, and 5eca8b6: "[PGO][HIP] Stop pulling ROCm.o into every PGO host link (#200101)" "[compiler-rt][profile] Add COMPILER_RT_BUILD_PROFILE_ROCM option (#200127)" "[PGO][HIP] Skip ROCm interceptor in profile-only compiler-rt builds (#200111)" "[PGO][HIP] Fix profile-only Windows link by gating ROCm interceptor macro (#200859)"
This was referenced Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
InstrProfilingPlatformROCm.cpp (added in 5db1364 or #177665) is currently built into every non-baremetal libclang_rt.profile, but not all hosts support it (e.g. it fails to link on Darwin, where __llvm_write_custom_profile is unavailable).
Add a COMPILER_RT_BUILD_PROFILE_ROCM CMake option (defaulting off on Apple, on elsewhere) to allow that host to opt out.